<?php
/**
 * PHP By Example
 *
 * @copyright 2014 Michel Corne <mcorne@yahoo.com>
 * @license   http://www.opensource.org/licenses/gpl-3.0.html GNU GPL v3
 */
?>

<?php
    $this->_output->display_function_title();
    require "$this->application_path/views/php_manual.phtml";
?>

<form method="post">
  <div class="block blue_border nowrap"><?=$this->_input->display_source_code();?></div>

  <div>
    <input <?php if ($this->_params->translation_in_action == 1401):?>
             class="button submit highlight_translation_in_action"
           <?php else:?>
             class="button submit"
           <?php endif;?>
           name="submit"
           type="submit"
           value="<?=$this->_message_translation->translate('Execute the function');?>" />
  </div>

</form>

<?php if ($this->errors):?>
  <div class="title red"><?=$this->_message_translation->translate('Result');?></div>
<?php else:?>
  <div class="title green"><?=$this->_message_translation->translate('Result');?></div>
<?php endif;?>

<?php if ($this->result):?>

  <div class="block green_border">
    <code>
      <table>

        <?php foreach ($this->result as $var_name => $value):?>
          <tr>
            <td class="variable">$<?=$var_name;?></td>
            <td class="operator">=</td>
            <td><?=$this->_output->display_var_value($value);?></td>
          </tr>
        <?php endforeach;?>

      </table>
    </code>
  </div>

<?php endif;?>

<?php if ($this->errors):?>

  <div class="block red_border">
    <table class="errors">

      <?php foreach ($this->errors as $error):?>
        <tr>
          <td class="error_code"><?=$this->_output->display_error_code($error['code']);?></td>
          <td>:</td>
          <td>
            <?=in_array($error['code'], [E_USER_ERROR, E_USER_NOTICE, E_USER_WARNING, null]) ?
                   $error['message'] :
                   htmlspecialchars($error['message']);
            ?>
          </td>
        </tr>
      <?php endforeach;?>

    </table>
  </div>

<?php endif;?>

<?php if ($this->examples):?>

  <div class="title blue"><?=$this->_message_translation->translate('Examples');?></div>

  <div class="block blue_border">
       <table>

         <?php foreach ($this->examples as $example_id => $example):?>
           <tr>

             <td>
               <code>
                 <a class="blue" href="<?=$this->_output->display_url('function', $this->_application->function_name);?>?example=<?=$example_id + 1;?>">
                   #<?=$example_id + 1;?>
                 </a>
               </code>
             </td>

             <td>
               <code class="blue">
                 <?=$this->_application->function_name;?>
               </code>
             </td>

             <td><?=$this->_output->display_example_values($example);?></td>

           </tr>
         <?php endforeach;?>

       </table>
  </div>

<?php endif;?>

<?php
if ($this->_see_also_function->see_also_functions) {
    $this->_output->display_function_list(
        $this->_see_also_function->see_also_functions,
        $this->_message_translation->translate('See also'),
        'blue');
}
?>
